Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace C4F.DevKit.Calendar.Controls
	Friend Partial Class SelectAttendees
		Inherits Form
		Public ReadOnly Property SelectedAttendees() As String
			Get
				Return txtSelectedAttendees.Text
			End Get
		End Property

		Public Sub New(ByVal contacts As List(Of Attendee), ByVal currentAttendeeText As String)
			InitializeComponent()

			bindingSource1.DataSource = contacts
			grdAttendees.Columns(NameColumn.Index).DataPropertyName = "Name"
			grdAttendees.Columns(EmailColumn.Index).DataPropertyName = "EmailAddress"
			txtSelectedAttendees.Text = currentAttendeeText

			If (Not txtSelectedAttendees.Text.Trim().EndsWith(";")) Then
				txtSelectedAttendees.Text &= "; "
			End If
		End Sub

		Private Sub grdAttendees_CellDoubleClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles grdAttendees.CellDoubleClick
			If e.RowIndex <> -1 Then
				Dim name As String = grdAttendees.Rows(e.RowIndex).Cells(NameColumn.Name).Value.ToString()
				Dim email As String = grdAttendees.Rows(e.RowIndex).Cells(EmailColumn.Name).Value.ToString()

				If String.IsNullOrEmpty(email) Then
					txtSelectedAttendees.Text += String.Format("{0}; ", name)
				Else
					txtSelectedAttendees.Text += String.Format("{0} <{1}>; ", name, email)
				End If
			End If
		End Sub
	End Class
End Namespace
